package test.fun;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.util.ArrayList;

import static test.fun.GetConnet.connection;

/**
 * ClassName: PutFun
 * Package: test.fun
 * Description:
 *               TODO 插入数据的操作
 * @Author ChenJun
 * @Create 2023/4/23 9:31
 * @Version 1.0
 */
public class PutFun {
    //TODO 插入数据的操作
    public static void putData(String tableName, String rowKey, String cf, String column, String value) throws IOException {

        //获取表名
        Table table = connection.getTable(TableName.valueOf(tableName));

        //创建put集合
        Put put = new Put(rowKey.getBytes());

        //添加具体的列信息
        put.addColumn(cf.getBytes(), column.getBytes(), value.getBytes());

        Put put1 = new Put("1002".getBytes());

        put1.addColumn(cf.getBytes(), column.getBytes(), value.getBytes());

        //添加多个数据
        ArrayList<Put> puts = new ArrayList<>();
        puts.add(put);
        puts.add(put1);

        //执行put操作
        table.put(puts);

        //关闭连接
        table.close();
    }
}
